{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>码商通道管理</legend>
    </fieldset> 
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}  
<script type="text/html" id="lvte">
   {{d.rate}} %
</script>
<script type="text/html" id="state">
    {{# if(d.state==0){ }}
        <span class="green">启动</span>
    {{# }else{ }}
        <span class="red">关闭</span>
    {{# } }}  
</script> 
<script type="text/html" id="open">
    <input type="checkbox" name="open" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="open" {{ d.open == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="action">
    <a href="{:url('edit')}?id={{d.id}}" class="layui-btn layui-btn-xs">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery;
        userid="{$userid}";
        shopid="{$shopid}";
        agentid="{$agentid}";
        var tableIn = table.render({
            id: 'ad',
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            page:true,
            cols: [[ 
                // {field: 'id', title: '{:lang("id")}',align: 'center', width: 80, fixed: true},
                {field: 'title', title: '通道名称',align: 'center', width: 120, fixed: true},
                {field: 'cionname', title: '币种',align: 'center', width: 128, fixed: true},
                {field: 'price', title: '单价',align: 'center', width: 100, fixed: true},
                {field: 'rate', title: '通道手续费', align: 'center', width:120,fixed: true,templet: '#lvte'},
                {field: 'shopname', title: '所属商户',align: 'center',width:156},
                // {field: 'money_today', title: '今日收款',align: 'center',width:130},
                {field: 'money_total', title: '累计收款',align: 'center',width:130},
                {field: 'username', title: '所属码商', align: 'center', width:130,},
                {field: 'mobile', title: '码商联系方式', align: 'center', width:138}, 
                {field: 'addtime', title: '{:lang("add")}{:lang("time")}',width: 150}, 
                {field: 'open', align: 'center', title: '{:lang("status")}', width: 100, toolbar: '#open'},
                {field: 'state', align: 'center', title: '交易{:lang("status")}', width: 100,templet: '#state'},
                {width: 120, align: 'center', toolbar: '#action'}
            ]],
            limit:60,where: {userid:userid,shopid:shopid,agentid:agentid}
        });
        form.on('switch(open)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var open = obj.elem.checked===true?1:0;
            $.post('{:url("editState")}',{'id':id,'open':open},function (res) {
                layer.close(loading);
                if (res.status==1) {
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        tableIn.reload();
                    }); 
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        }); 
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'del'){
                layer.confirm('您确定要删除吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('del')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg('操作失败！',{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        }); 
    })
</script>